<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<script src="../vue.js"></script>
<style>
  .fade-enter-active,
  .fade-leave-active {
    transition: opacity .5s ease;
  }

  .fade-enter,
  .fade-leave-to {
    opacity: 0;
  }
</style>

<body>
  <div id="app">

    <a href="#" @click="componentName = 'login'" href="javascript;">login</a>
    <a href="#" @click="componentName = 'register'" href="javascript;">register</a>

    <transition name="fade" mode="out-in">
      <!-- 绑定is属性 -->
      <component :is="componentName"></component>
    </transition>
  </div>


  <!-- 定义登录组件的模板 -->
  <template id="loginTmp">
    <button>LOGIN</button>
  </template>


  <!-- 定义注册组件的模板 -->
  <template id="registerTmp">
    <button>REGISTER</button>
  </template>



  <script>
    // 注册登录组件
    Vue.component("login", {
      template: "#loginTmp",
    })
    // 注册注册组件
    Vue.component("register", {
      template: "#registerTmp",
    })

    var vm = new Vue({
      el: "#app",
      data: {
        componentName: "login"
      }
    })
  </script>

</body>

</html>